// 全局样式重置
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC",
    "WenQuanYi Micro Hei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: $text-color;
  background-color: $background-gray;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
}

// 链接样式
a {
  color: $primary-color;
  text-decoration: none;
  transition: color 0.2s ease;

  &:hover {
    color: $primary-hover;
  }
}

// 按钮基础样式
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: $border-radius-medium;
  font-size: $font-size-sm;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  // 主要按钮
  &.btn-primary {
    background-color: $primary-color;
    color: white;
    border-color: $primary-color;

    &:hover:not(:disabled) {
      background-color: $primary-hover;
      border-color: $primary-hover;
    }

    &:active {
      background-color: $primary-active;
      border-color: $primary-active;
    }
  }

  // 次要按钮
  &.btn-secondary {
    background-color: transparent;
    color: $text-color;
    border-color: $border-color;

    &:hover:not(:disabled) {
      background-color: $background-light;
      border-color: $primary-color;
      color: $primary-color;
    }
  }

  // 文本按钮
  &.btn-text {
    background-color: transparent;
    color: $text-secondary;
    border: none;
    padding: 4px 8px;

    &:hover:not(:disabled) {
      color: $primary-color;
      background-color: rgba(0, 132, 255, 0.06);
    }
  }
}

// 输入框样式
.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid $border-color;
  border-radius: $border-radius-medium;
  font-size: $font-size-sm;
  line-height: 1.5;
  color: $text-color;
  background-color: $background-color;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;

  &:focus {
    outline: none;
    border-color: $primary-color;
    box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.1);
  }

  &::placeholder {
    color: $text-light;
  }

  &:disabled {
    background-color: $background-light;
    color: $text-light;
    cursor: not-allowed;
  }
}

// 卡片样式
.card {
  background-color: $background-color;
  border-radius: $border-radius-large;
  box-shadow: $shadow-light;
  overflow: hidden;
  transition: box-shadow 0.2s ease;

  &:hover {
    box-shadow: $shadow-medium;
  }
}

// 分割线
.divider {
  height: 1px;
  background-color: $border-color;
  margin: 16px 0;

  &.vertical {
    width: 1px;
    height: auto;
    margin: 0 16px;
  }
}

// 文本省略
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-ellipsis-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-ellipsis-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
}

// 工具类
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.cursor-pointer {
  cursor: pointer;
}

// 响应式工具类
@media (max-width: 768px) {
  .hidden-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .hidden-desktop {
    display: none !important;
  }
}

// 滚动条样式
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;

  &:hover {
    background: rgba(0, 0, 0, 0.3);
  }
}

// 加载动画
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid $border-color;
  border-top: 2px solid $primary-color;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

// ===== Element Plus 组件样式覆盖 =====

// 按钮组件
.el-button {
  &.el-button--primary {
    background-color: $primary-color;
    border-color: $primary-color;

    &:hover {
      background-color: $primary-hover;
      border-color: $primary-hover;
    }

    &:active {
      background-color: $primary-active;
      border-color: $primary-active;
    }
  }
}

// 输入框组件
.el-input {
  .el-input__wrapper {
    border-radius: $border-radius-medium;

    &:hover {
      border-color: $primary-color;
    }

    &.is-focus {
      border-color: $primary-color;
      box-shadow: 0 0 0 2px rgba(185, 43, 39, 0.1);
    }
  }
}

// 下拉菜单
.el-dropdown-menu {
  border-radius: $border-radius-large;
  box-shadow: $shadow-medium;

  .el-dropdown-menu__item {
    &:hover {
      background-color: rgba(185, 43, 39, 0.1);
      color: $primary-color;
    }
  }
}

// 消息提示
.el-message {
  border-radius: $border-radius-large;
  box-shadow: $shadow-medium;

  &.el-message--success {
    background-color: rgba(82, 196, 26, 0.1);
    border-color: $success-color;
  }

  &.el-message--warning {
    background-color: rgba(250, 173, 20, 0.1);
    border-color: $warning-color;
  }

  &.el-message--error {
    background-color: rgba(255, 77, 79, 0.1);
    border-color: $error-color;
  }
}

// 对话框
.el-dialog {
  border-radius: $border-radius-large;

  .el-dialog__header {
    border-bottom: 1px solid $border-color;
    padding: $spacing-lg;
  }

  .el-dialog__body {
    padding: $spacing-lg;
  }
}

// 表格
.el-table {
  .el-table__header {
    background-color: $background-light;
  }

  .el-table__row {
    &:hover {
      background-color: rgba(185, 43, 39, 0.05);
    }
  }
}

// 分页
.el-pagination {
  .el-pager li {
    &.is-active {
      background-color: $primary-color;
      color: white;
    }
  }

  .btn-next,
  .btn-prev {
    &:hover {
      color: $primary-color;
    }
  }
}

// 单选按钮组
.el-radio-group {
  display: inline-flex;
  align-items: center;

  .el-radio-button {
    position: relative;
    margin: 0;

    // 折叠相邻按钮的边框
    & + .el-radio-button {
      margin-left: -1px;
    }

    // 隐藏原始单选框
    .el-radio-button__original-radio {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }

    // 激活态（类名+兄弟选择器，提升覆盖力）
    &.is-active {
      .el-radio-button__original-radio:not(:disabled) + .el-radio-button__inner {
        background-color: $primary-color;
        border-color: $primary-color;
        color: white;
        box-shadow: -1px 0 0 0 $primary-color;
      }

      // 兜底：仅类名也应用颜色（防止某些场景未命中兄弟选择器）
      .el-radio-button__inner {
        background-color: $primary-color;
        border-color: $primary-color;
        color: white;
      }
    }

    // 选中态（无需 is-active 类也能生效）
    .el-radio-button__original-radio:checked + .el-radio-button__inner {
      background-color: $primary-color;
      border-color: $primary-color;
      color: white;
      box-shadow: -1px 0 0 0 $primary-color;
    }

    .el-radio-button__inner {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 6px 12px;
      height: 32px;
      line-height: 1;
      border: 1px solid $border-color;
      border-radius: 0;
      transition: all 0.2s ease;
      color: $text-secondary;
      background-color: white;
      cursor: pointer;

      &:hover {
        color: $primary-color;
      }
    }

    &:first-child {
      .el-radio-button__inner {
        border-left: 1px solid $border-color;
        border-top-left-radius: $border-radius-medium;
        border-bottom-left-radius: $border-radius-medium;
      }
    }

    &:last-child {
      .el-radio-button__inner {
        border-top-right-radius: $border-radius-medium;
        border-bottom-right-radius: $border-radius-medium;
      }
    }
  }
}
